<?php

namespace App\Containers\AppSection\Pledge\UI\API\Transformers;

use App\Containers\AppSection\Pledge\Models\Property;
use App\Containers\AppSection\Pledge\UI\API\Transformers\Properties\ApartmentTransformer;
use App\Containers\AppSection\Pledge\UI\API\Transformers\Properties\BuildingTransformer;
use App\Containers\AppSection\Pledge\UI\API\Transformers\Properties\HouseTransformer;
use App\Containers\AppSection\Pledge\UI\API\Transformers\Properties\LandTransformer;
use App\Containers\AppSection\Pledge\UI\API\Transformers\Properties\PremiseTransformer;
use App\Containers\AppSection\Type\UI\API\Transformers\TypeTransformer;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Item;

class PropertyTransformer extends Transformer
{
    protected array $defaultIncludes = [
        'apartment', 'house', 'premise', 'land', 'building', 'type'
    ];

    /**
     * @param Property $t
     * @return array
     */
    public function transform(Property $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'type_key' => $t->type_key,
        ];
    }

    public function includeApartment(Property $t): ?Item
    {
        return $this->nullableItem($t->apartment, new ApartmentTransformer);
    }

    public function includeHouse(Property $t): ?Item
    {
        return $this->nullableItem($t->house, new HouseTransformer);
    }

    public function includePremise(Property $t): ?Item
    {
        return $this->nullableItem($t->premise, new PremiseTransformer);
    }

    public function includeLand(Property $t): ?Item
    {
        return $this->nullableItem($t->land, new LandTransformer);
    }

    public function includeBuilding(Property $t): ?Item
    {
        return $this->nullableItem($t->building, new BuildingTransformer);
    }

    public function includeType(Property $t): Item
    {
        return $this->item($t->type, new TypeTransformer);
    }
}
